<?php
namespace Admin\Controller;
use Admin\Logic\Controller\MainController;
use Admin\Model\HospitalModel;
class HospitalController extends MainController {
    /**
     * @var HospitalModel
     */
    protected $hospitalModel = null;
    public function _initialize(){
        $this->hospitalModel = new HospitalModel();
    }
    public function hospitalList(){
        $this->assign ( 'hospitalList',  $this->hospitalModel->HospitalList() );
        $this->display();
    }
    public function hospitalAdd(){
        if(!IS_POST){
            $this->display();
        }else{
            $data['name'] = I("post.name",'','string');
            $data['province'] = I("post.province",'','int');
            $data['city'] = I("post.city",'','int');
            $data['area'] = I("post.area",'','int');
            $data['address'] = I("post.address",'','string');
            $data['telephone'] = I("post.telephone",'','string');
            $data['phone'] = I("post.phone",'','string');
            $data['remark'] = I("post.remark",'','string');
            $res = $this->hospitalModel->HospitalAdd($data);
            if($res){
                $this->success('添加成功',U("Hospital/hospitalList"));
            }else{
                $this->error('删除失败');
            }
        }
    }
    public function hospitalEdit(){
    	if(!IS_POST){
            $id = I('get.id',null,'int');
            $id || die;
            $this->assign ( 'info',  $this->hospitalModel->HospitalFind($id) );
    	    $this->display();
        }else{
//            var_dump($_REQUEST);die;
            $res = $this->hospitalModel->HospitalEdit();
            if($res){
                $this->success("保存成功");
            }else{
                $this->error('保存失败');
            }
        }
    }
    public function hospitalDelete(){
//        var_dump(I('get.'));die;
        $id = I('get.id',null,'int');
        if($id){
            $res = $this->hospitalModel->HospitalDel($id);
        }
        if($res){
            $this->success("删除成功");
        }else{
            $this->error("删除失败");
        }
    }
}
